<div class="warpper">
    <div class="title">
        <div id="url" class="s-back" data-url="${ctx}/admin/user/list">返回</div>
        权限 - 添加用户
    </div>
    <div class="content">
        <div class="explanation" id="explanation">
            <div class="ex_tit"><i class="sc_icon"></i><h4>操作提示</h4><span id="explanationZoom" title="收起提示"></span>
            </div>
            <ul>
                <li>可从管理平台手动添加一名新会员，并填写相关信息。</li>
                <li>标识“<em>*</em>”的选项为必填项，其余为选填项。</li>
                <li>新增会员后可从会员列表中找到该条数据，并再次进行编辑操作，但该会员名称不可变。</li>
            </ul>
        </div>
        <div class="flexilist">
            <div class="common-content">
                <div class="mian-info">
                    <div class="switch_info">
                        <form class="frm" data-option="${action!''}">
                            <input type="hidden" id="id" name="id" value="${id!''}">
                            <div class="item">
                                <div class="label"><span class="require-field">*</span>&nbsp;账号：</div>
                                <div class="label_value">
                                    <input type="text" id="account" name="account" class="text" value=""
                                           autocomplete="off" maxlength="20" required/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label"><span class="require-field">*</span>&nbsp;昵称：</div>
                                <div class="label_value">
                                    <input type="text" name="user_name" class="text" value="" id="user_name" maxlength="30" required/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label"><span class="require-field">*</span>&nbsp;电话：</div>
                                <div class="label_value">
                                    <input type="text" name="phone" id="phone" class="text" value="" maxlength="20" required/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">&nbsp;邮箱：</div>
                                <div class="label_value">
                                    <input type="text" name="email" id="email" class="text" value=""/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">&nbsp;微信：</div>
                                <div class="label_value">
                                    <input type="text" name="weixin" id="weixin" class="text" value=""/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">&nbsp;微博：</div>
                                <div class="label_value">
                                    <input type="text" name="weibo" id="weibo" class="text" value=""/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">&nbsp;QQ：</div>
                                <div class="label_value">
                                    <input type="text" name="qq" id="qq" class="text" value=""/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">&nbsp;职位：</div>
                                <div class="label_value">
                                    <input type="text" name="position" id="position" class="text" value=""/>
                                    <div class="form_prompt"></div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">性别：</div>
                                <div class="label_value">
                                    <div class="checkbox_items">
                                        <div class="checkbox_item">
                                            <input type="radio" class="ui-radio" name="sex" id="sex_1" value="1"
                                                   checked="">
                                            <label for="sex_1" class="ui-radio-label">男</label>
                                        </div>
                                        <div class="checkbox_item">
                                            <input type="radio" class="ui-radio" name="sex" id="sex_2" value="2"
                                                   checked="">
                                            <label for="sex_2" class="ui-radio-label">女</label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="item">
                                <div class="label">账号类型：</div>
                                <div class="label_value">
                                    <div id="user_grade" class="imitate_select select_w320">
                                        <div class="cite">普通用户</div>
                                        <ul>
                                            <li><a href="javascript:;" data-value="1" class="ftx-01">普通用户</a></li>
                                            <li><a href="javascript:;" data-value="2" class="ftx-01">管理员</a></li>
                                        </ul>
                                        <input name="user_type" type="hidden" value="0" id="user_type">
                                    </div>
                                </div>
                            </div>

                            <div class="item">
                                <div class="label">备注：</div>
                                <div class="label_value"><textarea type="text" name="remark" class="textarea"
                                                                   value="" autocomplete="off" placeholder="请输入备注信息"/>
                                </div>
                            </div>

                            <div class="item">
                                <div class="label">&nbsp;</div>
                                <div class="label_value info_btn">
                                    <a href="javascript:;" class="button" id="submitBtn"> 确定 </a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {

        $('form.frm').validate({

            errorPlacement:function(error, element){
                var error_div = element.parents('div.label_value').find('div.form_prompt');
                element.parents('div.label_value').find(".notic").hide();
                error_div.append(error);
            },
            messages : {
                account : {
                    required : '<i class="icon icon-exclamation-sign"></i> 账号不能为空',
                },
                user_name : {
                    required : '<i class="icon icon-exclamation-sign"></i> 昵称不能为空'
                },
                phone : {
                    required : '<i class="icon icon-exclamation-sign"></i> 手机号不能为空'
                }
            }, submitHandler: function(form) { alert("提交事件!");form.submit(); }
        });


        $("a#submitBtn").click(function () {
            var data = $("form.frm").serializeJson();
            var option = $("form.frm").attr("data-option");
            if(option=="add"){
                $.post("${ctx}/user/save", data, function(res){
                    if(res.code==0){
                        loadHtml("${ctx}/admin/user/success.jhtml?act=0&name="+data.account, false);
                    }else
                        alert(res.message);
                });
            }else if(option=="update"){
                $.post("${ctx}/user/update", data, function(res){
                    if(res.code==0){
                        loadHtml("${ctx}/admin/user/success.jhtml?act=1&name="+data.account, false);
                    }else
                        alert(res.message);
                });
            }

        });

        //查询用户信息
        if("${action!''}"=="update"){
            $.get("${ctx}/user/find",{id:$("input[id='id']").val()}, function(res){
                if(res.code==0){
                    $("form.frm").resetObjectForm(res.data);
                }else
                    alert(res.message);
            })
        }
    })
</script>